package cn.jly.spring.boot.cloud.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author lanyangji
 * @description test
 * @date 2020/12/9 上午 10:31
 */
public class TestMain {
    public static void main(String[] args) {
        String jdbcUrl = "jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8&serverTimezone=UTC";
        String driverClass = "com.mysql.jdbc.Driver";
        String username = "root";
        String password = "123456";

        Connection connection = null;
        PreparedStatement preparedStatement = null;

        String sql = "create table if not exists tbl_person(id int(11) primary key auto_increment, " +
                "name varchar(50) unique )";

        try {
            Class.forName(driverClass);
            connection = DriverManager.getConnection(jdbcUrl, username, password);
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.executeUpdate();
            System.out.println(sql);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != preparedStatement) {
                try {
                    preparedStatement.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (null != connection) {
                try {
                    connection.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }

    }
}
